-
Notifications
You must be signed in to change notification settings - Fork 3
Try to complete all TODO's #2
Conversation
include/socket_family.hpp
Outdated
| namespace method { | ||
|
|
||
| inline std::string getErrorMsg() | ||
| inline std::string getErrorMsg(int errorNumber) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const int errorNumber
src/socket.cpp
Outdated
|
|
||
| if (res == -1) { | ||
| throw std::runtime_error(net::method::getErrorMsg()); | ||
| if (res == -1 && errno != EINPROGRESS ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take out errno and use that for checks, send that into net::method::getErrorMsg(errno) too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, needs #include <errno.h> for errno - http://man7.org/linux/man-pages/man3/errno.3.html
src/socket.cpp
Outdated
| auto client = ::accept(sockfd, (sockaddr *) peerAddr.get(), &peerAddrSize); | ||
|
|
||
| if (client == -1) { | ||
| if (client == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, take out errno into another var.
src/socket.cpp
Outdated
|
|
||
| if (client == -1) { | ||
| if (client == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { | ||
| // TODO: Check for client == EAGAIN or EWOULDBLOCK and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete these comments.
src/socket.cpp
Outdated
| const auto currentErrNo = errno; | ||
| errno = 0; | ||
| if (client == -1 && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) { | ||
| throw std::runtime_error(net::method::getErrorMsg(currentErrNo)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No way of finding out if non-blocking error.
src/socket.cpp
Outdated
| const auto currentErrNo = errno; | ||
| errno = 0; | ||
| if (written == -1 && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) { | ||
| throw std::runtime_error(net::method::getErrorMsg(currentErrNo)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No way of finding out if non-blocking error.
src/socket.cpp
Outdated
| const auto currentErrNo = errno; | ||
| errno = 0; | ||
| if (sent == -1 && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) { | ||
| throw std::runtime_error(net::method::getErrorMsg(currentErrNo)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No way of finding out if non-blocking error.
src/socket.cpp
Outdated
| const auto currentErrNo = errno; | ||
| errno = 0; | ||
| if (sent == -1 && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) { | ||
| throw std::runtime_error(net::method::getErrorMsg(currentErrNo)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No way of finding out if non-blocking error.
src/socket.cpp
Outdated
|
|
||
|
|
||
| std::string Socket::read(const int _bufSize) const | ||
| std::string Socket::read(const int _bufSize, bool *_isSpecialErrorInNonBlocking) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameter name quite big... _ErrorNB seems fine.
src/socket.cpp
Outdated
| throw std::runtime_error(net::method::getErrorMsg()); | ||
| if ( !_isSpecialErrorInNonBlocking || (_isSpecialErrorInNonBlocking && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK)) // blocking & non blocking failure case | ||
| throw std::runtime_error(net::method::getErrorMsg(currentErrNo)); | ||
| // else if ( _isSpecialErrorInNonBlocking && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) // non blocking failure case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comments, use proper braces { } for if else statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simplify logic, let compiler do the work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not throws invalid_argument in case nullptr is sent/or last param is ignored and non-blocking error occurs.
src/socket.cpp
Outdated
| // TODO: Check for bytes == EAGAIN or EWOULDBLOCK and | ||
| // don't throw exception in that case. | ||
| throw std::runtime_error(net::method::getErrorMsg()); | ||
| if ( !_isSpecialErrorInNonBlocking || (_isSpecialErrorInNonBlocking && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK)) // blocking & non blocking failure case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicitly check for != nullptr instead of executing bool operator. Makes intent clear.
src/socket.cpp
Outdated
| // TODO: Check for recvd == EAGAIN or EWOULDBLOCK and | ||
| // don't throw exception in that case. | ||
| throw std::runtime_error(net::method::getErrorMsg()); | ||
| if ( !_isSpecialErrorInNonBlocking || (_isSpecialErrorInNonBlocking && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here.
No description provided.